package cn.tedu.charging.order.mqtt;


import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
public class MqttProducter {

    @Autowired
    private MqttClient mqttClient;


    public Boolean sendMqtt(String topic ,String message){
        Boolean isSuccess=false;
        try {
            mqttClient.publish(topic,message.getBytes(),0,true);
            isSuccess=true;
        } catch (MqttException e) {
            throw new RuntimeException(e);
        }
        return isSuccess;
    }
}
